package com.atmc.controller;

import com.atmc.bean.Bill;
import com.atmc.service.BillService;
import com.atmc.service.OpenFeignService;

import com.github.pagehelper.IPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class BillFeignController {
    @Autowired
    BillService billService;
    @Autowired
    OpenFeignService openFeignService;

    //远程接口调用服务，返回list集合数据 视图渲染到页面
    @RequestMapping("/html/articletype-list")
    public String toArticletype(Model model) {
        List<Bill> list = billService.selectAll();
//        List<Bill> list = openFeignService.select();
        model.addAttribute("msg",list);
        return "bill/articletype-list";
    }
    //远程接口调用服务，返回list集合数据 视图渲染到页面
    @RequestMapping("/html/article-list")
    public String toArticlelist(Model model) {
        List<Bill> list = openFeignService.select();
        model.addAttribute("msg",list);
        return "bill/article-list";
    }
    //添加一个账单记录
    @RequestMapping("/html/addOneRecord")
    public String toarticleList(@RequestParam("goods_name") String goods_name, @RequestParam("goods_unit") String goods_unit,
                                @RequestParam("goods_num") Integer goods_num, @RequestParam("total_amount") Integer total_amount,
                                @RequestParam("supplier") String supplier, @RequestParam("payment") String payment) {


        Bill bill=new Bill(null,goods_name,goods_unit,goods_num,total_amount,supplier,payment,null,null);
        billService.insertOne(bill);
        return "bill/insertsuccess";


    }
    //修改一条账单记录
    @RequestMapping("/tobillupdate/{goods_name}")
    public String toBillUpodate(@PathVariable("goods_name") String goods_name, Model model){
        model.addAttribute("goodsname",goods_name);

        return "bill/billupdate";
    }
    //修改后返回页面
    @RequestMapping("/tobillupdatesuccess")
    public String tbillupdatesuccess(@RequestParam("goods_name") String goods_name, @RequestParam("goods_unit") String goods_unit,
                                     @RequestParam("goods_num") Integer goods_num, @RequestParam("total_amount") Integer total_amount,
                                     @RequestParam("supplier") String supplier, @RequestParam("payment") String payment
            , Model model

    ){
        Bill bill=new Bill(null,goods_name,goods_unit,goods_num,total_amount,supplier,payment,null,null);
        billService.updateOne(bill);
        List<Bill> list = openFeignService.select();
        model.addAttribute("msg",list);
        return "bill/article-list";
    }
    //删除一条账单记录
    @RequestMapping("/tobilldelete/{bill_id}")
    public String toBillDelete(@PathVariable("bill_id") int bill_id, Model model){
        List<Bill> list = openFeignService.select();
        model.addAttribute("msg",list);
        billService.deleteOne(bill_id);
        return "bill/article-list";
    }



}
